﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SubBranchForm.aspx.cs"
    Inherits="FBKPI.Forms.SubBranchForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#divBrowseLocation").hide();
            $("#divBrowseLocation").dialog({ autoOpen: false, width: 900, height: 300, modal: true, resizable: false });

            $("#btn_save").click(function () {
                var param = "?";
                var isActive = 'false';

                $('#form1 td input:checked').each(function () {
                    var $cb = $(this);
                    if ($cb.attr('id') == 'chk_active') {
                        isActive = 'true';
                    }
                });

                param = param + "action=save";
                param = param + "&ID=" + $("#hfId").val();
                param = param + "&Code=" + $("#txt_code").val();
                param = param + "&Description=" + $("#txt_description").val();
                param = param + "&isActive=" + isActive;
                param = param + "&Location=" + $("#txt_locationid").val();
                param = param + "&WarehouseID=" + $("#txt_warehouseid").val();
                param = param + "&ClassBranch=" + $("#txt_classbranch").val();
                param = param + "&Address=" + $("#txt_address").val();
                param = param + "&Phone=" + $("#txt_phone").val();
                param = param + "&CurrUser=" + $("#txt_user").val();
                ProcessRequest("SubBranchHandler.ashx" + param, "#divdetail", "#SubBranchTable");
                return false;
            });


            $("#btn_delete").click(function () {
                //                if (confirm('Are you sure to delete this record?')) {
                //                    var param = "?";
                //                    param = param + "action=delete";
                //                    param = param + "&ID=" + $("#txt_id").val();
                //                    param = param + "&CurrUser=" + $("#txt_user").val();
                //                    ProcessRequest("SubBranchHandler.ashx" + param, "#divdetail", "#SubBranchTable");
                //                    return false;
                //                }

                $.msgBox.confirm("Benar data akan dihapus ?", function () {
                    var param = "?";
                    param = param + "action=delete";
                    param = param + "&ID=" + $("#hfId").val();
                    param = param + "&CurrUser=" + $("#txt_user").val();
                    ProcessRequest("SubBranchHandler.ashx" + param, "#divdetail", "#SubBranchTable");
                    return false;
                }, false);

                return false;
            });

            $("#btn_close").click(function () {
                parent.$("#divdetail").dialog("close");
                return false;
            });

            $("#btn_BrowseLocation").click(function () {
                $("#divBrowseLocation").dialog("option", "title", '<span class="header-text">Select Branch</span>');
                $("#divBrowseLocation").dialog("open");
                $('#location').dataTable({
                    "oLanguage": {
                        "sZeroRecords": "No records to display",
                        "sSearch": "Search"
                    },
                    "bSort": false,
                    "bPaginate": true,
                    "bAutoWidth": true,
                    "bProcessing": true,
                    "bServerSide": true,
                    "bDestroy": true,
                    "bJQueryUI": true,
                    "sPaginationType": "full_numbers",
                    "bDeferRender": true,
                    "fnServerData": function (sSource, aoData, fnCallback) {
                        $.ajax({
                            "dataType": 'json',
                            "type": "GET",
                            "url": "../Serializer/LocationSerializer.ashx?CurrUser=" + $("#txt_user").val(),
                            "data": aoData,
                            "success": fnCallback
                        });
                    },
                    "aoColumns": [
                        { "mData": "No" },
                        { "mData": "Description" },
                        { "mData": "ORGID" },
                        { "mData": "isActive" },
                        { "mData": "ID" }
                    ],
                    "aoColumnDefs":
                    [
                        { "fnRender":
                            function (oObj) {
                                return "<a href=\"#\" onclick=\"PickLocation('" + oObj.aData["ID"] + "','" + oObj.aData["Description"] + "')\"><img src='../images/ok.png' /></a>";
                            },
                            "aTargets": [4]
                        },
                        { "sClass": "center", "aTargets": [0, 2, 3, 4] },
                        { "fnRender":
                            function (oObj) {
                                if (oObj.aData["isActive"] == 'True') {
                                    return "<img src='../images/check.png' />"
                                }
                                else {
                                    return "<img src='../images/cross.png' />"
                                }
                            },
                            "aTargets": [3]
                        }
                    ]
                });

                //mark selected row
                $('body').on("click", '#location tbody tr', function () {
                    $('#location tbody tr').removeClass("row_selected");
                    $(this).addClass("row_selected");
                });
                $(".dataTables_filter input").focus();
                return false;
            });

            PickLocation = function (LocationID, LocationDescription) {
                $("#txt_location").val(LocationDescription);
                $("#txt_locationid").val(LocationID);
                $("#divBrowseLocation").dialog("close");
            }
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="subbranchformarea" class="ui-widget-content padding5px ui-corner-all">
        <table class="dialogTable" width="100%">
            <tr>
                <td width="50%">
                    <table>
                        <tr runat="server" visible="false">
                            <td width="140px">
                                ID
                            </td>
                            <td class="Separator">
                                :
                            </td>
                            <td>
                                <asp:TextBox ID="txt_id" runat="server" ReadOnly="true"></asp:TextBox>
                            </td>
                        </tr>
                         <tr>
                            <td>
                                Branch
                            </td>
                            <td>
                                :
                            </td>
                            <td>
                                <asp:TextBox ID="txt_location" runat="server" ReadOnly="true" Width="300" class="mandatory"></asp:TextBox>
                                <button id="btn_BrowseLocation" class="ui-button ui-state-default">
                                    <span class="ui-button ui-icon ui-icon-newwin"></span>
                                </button>
                                <input type="hidden" id="txt_locationid" runat="server" />
                            </td>
                        </tr>
                         <tr>
                            <td>
                                Description
                            </td>
                            <td>
                                :
                            </td>
                            <td>
                                <asp:TextBox ID="txt_description" runat="server" Width="300" class="mandatory"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Code
                            </td>
                            <td>
                                :
                            </td>
                            <td>
                                <asp:TextBox ID="txt_code" runat="server" class="mandatory"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Org ID
                            </td>
                            <td>
                                :
                            </td>
                            <td>
                                <asp:TextBox ID="txt_orgid" runat="server" class="mandatory"></asp:TextBox>
                            </td>
                        </tr>
                       
                        <tr>
                            <td>
                                is Active
                            </td>
                            <td>
                                :
                            </td>
                            <td>
                                <asp:CheckBox ID="chk_active" Checked="true" runat="server" />
                            </td>
                        </tr>
                       
                    </table>
                </td>
                <td width="50%">
                    <table>
                        <tr>
                            <td width="140px">
                                Class Branch
                            </td>
                            <td class="Separator">
                                :
                            </td>
                            <td>
                                <asp:TextBox ID="txt_classbranch" runat="server"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Warehouse ID
                            </td>
                            <td>
                                :
                            </td>
                            <td>
                                <asp:TextBox ID="txt_warehouseid" runat="server"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Address
                            </td>
                            <td>
                                :
                            </td>
                            <td>
                                <asp:TextBox ID="txt_address" runat="server" class="longText"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Phone
                            </td>
                            <td>
                                :
                            </td>
                            <td>
                                <asp:TextBox ID="txt_phone" runat="server"></asp:TextBox>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
    <br />
    <%--  <div id="AuditInformation" class="ui-widget-content padding5px ui-corner-all">
        <b style="margin-left: 5px">Audit Information</b>
        <table class="dialogTable">
            <tr>
                <td width="140px">
                    Last Modified Date
                </td>
                <td class="Separator">
                    :
                </td>
                <td>
                    <asp:TextBox ID="txt_lastmodifieddate" runat="server" ReadOnly="true"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Last Modified By
                </td>
                <td>
                    :
                </td>
                <td>
                    <asp:TextBox ID="txt_lastmodifiedby" runat="server" ReadOnly="true"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Create Date
                </td>
                <td>
                    :
                </td>
                <td>
                    <asp:TextBox ID="txt_createdate" runat="server" ReadOnly="true"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Create By
                </td>
                <td>
                    :
                </td>
                <td>
                    <asp:TextBox ID="txt_createby" runat="server" ReadOnly="true"></asp:TextBox>
                </td>
            </tr>
        </table>
    </div>--%>
    <div id="divBrowseLocation" class="ui-widget-content padding5px ui-corner-all">
        <table cellpadding="0" cellspacing="0" border="0" class="display" id="location">
            <thead>
                <tr>
                    <th>
                        No
                    </th>
                    <th>
                        Description
                    </th>
                    <th>
                        ORG ID
                    </th>
                    <th>
                        is Active
                    </th>
                    <th>
                    </th>
                </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    </div>
    <br />
    <button id="btn_save" class="button save">
        Save
    </button>

     <button id="btn_close" class="button close">
        Close
    </button>
    <%--<button id="btn_delete" class="ui-button ui-corner-all ui-button ui-state-default ui-button-text-icon-primary"
        runat="server">
        <span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span>
        <label class="ui-button-text">
            Delete</label>
    </button>--%>
    <asp:HiddenField ID="hfId" runat="server" Value="0" />
    </form>
</body>
</html>
